package com.se7en.ufutil;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class StudyAdapter extends ArrayAdapter<StudyComment> {

	Context context;
	int layoutResourceID;
	StudyComment[] comments = null;
	
	public StudyAdapter(Context context, int layoutResourceID, StudyComment[] data) {
		super(context, layoutResourceID, data);
		this.context = context;
		this.layoutResourceID = layoutResourceID;
		this.comments = data;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		
		View row = convertView;
        StudyHolder holder = null;
        
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceID, parent, false);
            
            holder = new StudyHolder();
            holder.dateTitle = (TextView)row.findViewById(R.id.datetext);
            holder.txtTitle = (TextView)row.findViewById(R.id.commentstext);
            
            row.setTag(holder);
        }
        else
        {
            holder = (StudyHolder)row.getTag();
        }
        
        StudyComment studycomment = comments[position];
        holder.txtTitle.setText(studycomment.comment);
        holder.dateTitle.setText(studycomment.date);
        
        return row;
    }
		
	
	
	
	static class StudyHolder
    {
        TextView dateTitle;
        TextView txtTitle;
    }
}
